package org.agile2soft.nexoma.tapestry.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

@IncludeJavaScriptLibrary("context:resources/js/FlashMessage.js")
public class FlashMessage {

    @Parameter(value="",defaultPrefix=BindingConstants.PROP)
    @Property
    private String value;

    @Inject
    private RenderSupport renderSupport;

    @Inject
    private ComponentResources componentResources;

    @AfterRender
    public void afterRender() {
        if ( value!=null && !value.equals("") ) {
            renderSupport.addInit("flashmessage",componentResources.getId());
        }
    }
}
